const { tool,time,api } = getApp();
Page({

    data: {
        topic: {},  // 课题信息
    },

    // 前往教师详情页
    toTeacher(e) {
        let { id } = e.currentTarget.dataset;
        api.navigateTo(`/pages/class/teacher/details/index?id=${id}`);
    },

    // 立即报名
    enroll() {
        api.getStorage('userInfo').then(info => {
            let { open_id } = info;
            tool.getSignRoot(open_id).then(res => {
                let { code,msg } = res;
                if (code == 200) {
                    tool.sign({ open_id,topic_id: this.data.topic.id }).then(res => {
                        api.showToast('报名成功','success');
                    })
                } else api.showToast(msg,'none');
            })
        })
    },

    // 页面加载
    onLoad(options) {
        let { id } = options;
        tool.getTopicDetails(id).then(topic => {
            this.setData({ topic });
        })
    },
    
})